package com.service;

import com.mapper.UinfoFollowMapper;
import com.model.UinfoFollow;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class UinfoFollowServiceImpl implements UinfoFollowService{

    @Resource
    private UinfoFollowMapper uinfoFollowMapper;


    @Override
    public int addOrRemoveUinfoFollow(UinfoFollow uinfoFollow) {

        UinfoFollow uinfoFollow1 = uinfoFollowMapper.selectByUid(uinfoFollow.getUid(),uinfoFollow.getFollowid());

        if (uinfoFollow1==null){
            uinfoFollow.setCdate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            uinfoFollowMapper.insert(uinfoFollow);
        }else {
            uinfoFollowMapper.deleteByPrimaryKey(uinfoFollow1.getId());
        }
        return 1;
    }

    @Override
    public UinfoFollow selectFollowInfo(Integer uid, Integer followid) {


        return uinfoFollowMapper.selectByUid(uid,followid);
    }
}
